package com.crape.account.bo.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.crape.account.bo.IAuthEmailBO;
import com.crape.common.constants.CrapePropertyConfigurer;
import com.crape.common.mail.EmailSentParam;
import com.crape.common.model.Account;
import com.crape.common.thread.EmailThreadPool;

@Service
public class AuthEmailBOImpl implements IAuthEmailBO {

    private EmailThreadPool emailThreadPool;

    public void setEmailThreadPool(EmailThreadPool emailThreadPool) {
        this.emailThreadPool = emailThreadPool;
    }

    @Override
    public void validateAccount(Account account) {
        if (account == null || account.getEmail() == null) {
            return;
        }
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("domain", CrapePropertyConfigurer.getProperty("webapp.domain"));
        model.put("account", account);
        EmailSentParam emailSentParams = new EmailSentParam();
        emailSentParams.setEmail(new String[] { account.getEmail() }); // 邮件收件地址列表
        emailSentParams.setModel(model); // vm模版的参数Map
        emailSentParams.setSubject("瓜朋网用户Email验证"); // 邮件的subject
        emailSentParams.setVmPath("validate.vm"); // 邮件发送的模版位置
        emailSentParams.setCcEmail(new String[] {});
        emailThreadPool.doMailSendWork(emailSentParams);
    }

    @Override
    public void missPassword(Account account) {
        if (account == null || account.getEmail() == null) {
            return;
        }
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("domain", CrapePropertyConfigurer.getProperty("webapp.domain"));
        model.put("account", account);
        EmailSentParam emailSentParams = new EmailSentParam();
        emailSentParams.setEmail(new String[] { account.getEmail() }); // 邮件收件地址列表
        emailSentParams.setModel(model); // vm模版的参数Map
        emailSentParams.setSubject("瓜朋网找回密码"); // 邮件的subject
        emailSentParams.setVmPath("missPassword.vm"); // 邮件发送的模版位置
        emailSentParams.setCcEmail(new String[] {});
        emailThreadPool.doMailSendWork(emailSentParams);
    }

}
